from Get_Token import Get_Token
import requests
import json
from Read_conifg import ReadConfig
from Get_Info import Get_Info

host=ReadConfig().get_http("url_khd")
drugUserId=Get_Info().Get_Drug_id()
uid=Get_Info().Get_login_id()
pharmacyId=Get_Info().Get_pharmacy_id()

def Add_Order():
    headers={"Token":Get_Token().Get_Khd_Token()}
    body={"drugUserId":drugUserId,"userId":uid,"uid":uid,"pickMethod":"自提","consignee":"null","mobile":"null","address":"null","province":"null","city":"null","area":"null","pharmacyId":pharmacyId,"pharmacistCode":"null","totalPayAmount":47810,"priceAmount":49010,"disAmount":1200,"medOrderFileVOList":[{"id":9380,"name":"0a874749-1941-4e71-92ad-e7c545fb8c72.jpg","originalName":"94b2d08d-267a-408c-9aa6-c5ec5a05433e.jpg","height":1160,"width":1640,"url":"/api/image/download?filename=/upload/pbm/pbm_khd_app_upload/20211228/94b2d08d-267a-408c-9aa6-c5ec5a05433e.jpg","length":242235,"lengthShow":"236.56","lengthUnit":"KB","type":"image/jpeg","description":"null","createTime":"2021-12-28 10:25:09","updateTime":"null","updateUserId":"null","deleted":"false","pmaId":"null"}],"pbmAgreementHiList":[{"agreementId":21,"content":"null","readTime":1640658346497,"readType":"阅读","statement":"true","statementName":"会员服务协议","type":"购药"},{"agreementId":22,"content":"null","readTime":1640658346497,"readType":"阅读","statement":"true","statementName":"授权书","type":"购药"},{"agreementId":"null","content":"null","readTime":1640658346499,"readType":"勾选","statement":"false","type":"购药"}],"medOrderGoods":{"medId":114481,"originalPrice":49010,"payAmount":47810,"number":1},"sendTime":"null","needBill":"false","medOrderBill":{"type":"单位","company":"null","taxCode":"null","name":"null"},"needIntegral":"false"}
    res=requests.post(url=host+"KhdMedOrder/submit",json=body,headers=headers)
    res_json=json.loads(res.text)
    # return res.text
    if res_json['msg']:
        if "dm" not in res_json['msg']:
            return "添加订单失败，"+res_json['msg']
        else:
            return res_json['data']
    else:
        return res_json['code']